//package com.honey.trip.producer;
//
//import BUSINESS_TYPE;
//import com.honey.trip.dao.*;
//import com.honey.trip.entity.*;
//import CardOrderExpiredVo;
//import VCTaskVo;
//import CardOrderService;
//import MailService;
//import DateUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//import org.springframework.boot.test.context.SpringBootTest;
//import org.springframework.test.context.junit4.SpringRunner;
//import org.springframework.transaction.annotation.Transactional;
//import org.springframework.util.CollectionUtils;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.List;
//
//@RunWith(SpringRunner.class)
//@SpringBootTest
//@Slf4j
//public class VIPCardTask {
//    @Resource
//    private CardOrderDao cardOrderDao;
//    @Resource
//    private DiligenceDegreeLogDao diligenceDegreeLogDao;
//    @Resource
//    private CardOrderService cardOrderService;
//    @Resource
//    private UserDao userDao;
//    @Resource
//    private SendService sendService;
//    @Resource
//    private HoneySugarLogDao honeySugarLogDao;
//    @Resource
//    private UserWalletDao userWalletDao;
//    @Resource
//    private MailService mailService;
//
////    @Test
////    //@Transactional
////    public void test() {
////        cardOrderService.dealExpiredCard(false);
////        List<User> users = userDao.findUserLevelDiscrepancyUsers();
////        if (CollectionUtils.isEmpty(users)) {
////            log.info("not found user level discrepancy");
////            return;
////        }
////        users.stream().forEach(user -> {
////            sendService.setDiligenceUpdate(user);
////        });
////
////        /*List<CardOrder> cardsBug = cardOrderDao.findCardsBug();
////
////        for (CardOrder cardOrder : cardsBug) {
////            Integer id = cardOrder.getId();
////            Integer userId = cardOrder.getUserId();
////            Integer diligenceCount = cardOrder.getDiligenceCount();
////            Integer parentFirst = cardOrder.getCardType();
////
////            DiligenceDegreeLog diligenceDegreeLog = new DiligenceDegreeLog();
////            diligenceDegreeLog.setUserId(userId);
////            diligenceDegreeLog.setRemark("会员卡加成");
////            diligenceDegreeLog.setIncreaseValue(new BigDecimal(diligenceCount));
////            diligenceDegreeLog.setCreateTime(DateUtils.strToDate("2019-11-28 01:30:00"));
////            diligenceDegreeLog.setTypeId(BUSINESS_TYPE.VIP_CARD);
////            diligenceDegreeLog.setRefId(id.toString());
////            diligenceDegreeLogDao.increase(diligenceDegreeLog);
////
////            DiligenceDegreeLog diligenceDegreeLog2 = new DiligenceDegreeLog();
////            diligenceDegreeLog2.setUserId(parentFirst);
////            diligenceDegreeLog2.setRemark("下级会员卡加成");
////            diligenceDegreeLog2.setIncreaseValue(new BigDecimal(diligenceCount).multiply(new BigDecimal("0.1")));
////            diligenceDegreeLog2.setCreateTime(DateUtils.strToDate("2019-11-28 01:30:00"));
////            diligenceDegreeLog2.setTypeId(BUSINESS_TYPE.VIP_CARD_SUBORDINATE);
////            diligenceDegreeLog2.setRefId(id.toString());
////            diligenceDegreeLogDao.increase(diligenceDegreeLog2);
////        }*/
////    }
//
//    @Test
//    @Transactional
//    public void Test() {
//        try {
//            //获取所有有效会员卡订单
//            List<VCTaskVo> allCardOrder = cardOrderDao.cardOrderTaskNeed();
//
//            //添加蜂蜜Log 日志
//            List<HoneySugarLog> honeySugarLog = new ArrayList<>();
//            List<UserWallet> userwallets = new ArrayList<>();
//            Integer count = 0;
//            if (allCardOrder.size() != 0) {
//                for (VCTaskVo vo :
//                        allCardOrder) {
//                    count++;
//                    HoneySugarLog hs = new HoneySugarLog();
//                    hs.setRemark("会员卡产出");
//                    hs.setTypeId(BUSINESS_TYPE.VIP_CARD_RETURN);
//                    hs.setRefId(vo.getId().toString());
//                    hs.setUserId(vo.getUserId());
//                    hs.setIncreaseValue(vo.getHoneySugar());
//                    honeySugarLog.add(hs);
//
//                    UserWallet userwallet = new UserWallet();
//                    userwallet.setUserId(vo.getUserId());
//                    userwallet.setHoneySugar(vo.getHoneySugar());
//                    userwallets.add(userwallet);
//                    if (count >= 3000) {
//                        count = 0;
//                        //更新用户钱包
//                        userWalletDao.updateUserWalletBatch(userwallets);
//                        //添加日志
//                        honeySugarLogDao.addHoneySugarLogList(honeySugarLog);
//                        log.info("[VIPCardTask.ViPCardProduce会员卡产出个数" + userwallets.size() + ";" + honeySugarLog.size());
//                        userwallets.clear();
//                        honeySugarLog.clear();
//                    }
//                }
//                //更新用户钱包
//                if (!CollectionUtils.isEmpty(userwallets)) {
//                    userWalletDao.updateUserWalletBatch(userwallets);
//                }
//                //添加日志
//                if (!CollectionUtils.isEmpty(honeySugarLog)) {
//                    honeySugarLogDao.addHoneySugarLogList(honeySugarLog);
//                }
//                log.info("[VIPCardTask.ViPCardProduce会员卡产出个数" + userwallets.size() + ";" + honeySugarLog.size());
//            }
//
//        } catch (Exception ex) {
//            log.info("[VIPCardTask.ViPCardProduce会员卡产出异常" + ex.toString());
//            mailService.sendSimpleMail("wangbowen@honeytrip.cn", "ViPCardProduce error", ex.getMessage());
//            throw new RuntimeException("ViPCardProduce error");
//        }
//    }
//}
